import { defineAsyncComponent } from 'vue';
const components = import.meta.glob('@/components/**/*.vue');

export default function install(app) {
  Object.entries(components).forEach(([key, value]) => {
    let paths = key.replace('/src/', '').split('/');
    let name = 'cm-' + paths[1];
    if (paths.length > 1 && paths[2] !== 'index.vue') {
      name += '-' + paths[2].replace('.vue', '');
    }
    name = name.replace(/[A-Z]/g, function(str){
      return '-' + str.toLowerCase();
    });
    app.component(name, defineAsyncComponent(value));
  });
}